package com.dream.service.recommender;

import com.dream.service.recommender.api.RecommenderService;
import com.dream.service.recommender.toolkits.utils.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by zhiji on 2016/3/15.
 */
public class RecomenderServiceFactory {

    private static ClassPathXmlApplicationContext appContext;

    static {
        try {//暂时方案
            String propertiesfile = "recommender-consumer.xml";
            appContext = new ClassPathXmlApplicationContext(propertiesfile);
        } catch (BeansException e) {
            e.printStackTrace();
        }
    }

    public static RecommenderService getRecommenderService(String beanName) {
        if(StringUtils.isEmpty(beanName)){
            return null;
        }
        return (RecommenderService) appContext.getBean(beanName);
    }
}
